package datos;



import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import conexion.Conexion;

public class AccionesRegistroPago {

	public static void addRegistroPago(RegistroPago rp){
		
		int idCliente = rp.getIdCliente();
		int idTipoPago = rp.getIdTipoPago();
		double monto = rp.getMonto();
		double saldoAnt = rp.getSaldoAnterior();
		String concepto= rp.getConcepto();
		try{
			Statement stm=Conexion.conectar().createStatement();
			stm.executeUpdate("insert into registro_pago (idCliente, idTipoPago, monto, fecha, saldoAnterior, concepto) values ("+idCliente+","+idTipoPago+","+monto+","+"now(),"+saldoAnt+",'"+concepto+"')");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public static ArrayList<RegistroPago> getRegistroPagoByCliente(int idCliente){
		RegistroPago rp=null;
		ArrayList<RegistroPago> registros=new ArrayList<RegistroPago>();
		
		try{
			Statement stm=Conexion.conectar().createStatement();
			ResultSet rs=stm.executeQuery("select * from registro_pago where idCliente="+idCliente);
			while(rs.next()){
				rp = new RegistroPago(rs.getInt("idCliente"),rs.getInt("idTipoPago"), rs.getDouble("monto"), rs.getDate("fecha"), rs.getString("concepto"));
				rp.setSaldoAnterior(rs.getDouble("saldoAnterior"));
				registros.add(rp);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return registros;
	}
		
	


}
